<script setup>
import {defineProps, ref,defineEmits} from "vue";
import {studentJoinCourse, updateCourseNumber} from "../../../../api/course/course.js";
import {ElMessage} from "element-plus";

const props=defineProps(['isJoinCourse']);
const emit=defineEmits(['close','list'])
const isJoinCourse = ref(false);
isJoinCourse.value = props.isJoinCourse;
const invite = ref('');

// 加入课程
const handleJoinCourse=async ()=>{
  await studentJoinCourse({invite:invite.value}).then(res=> {
    const  courseId=res.data;
    console.log(courseId);
    handleUpdateCourseNumber(courseId);
    ElMessage.success("加入课程成功");
    emit('close');
    emit('list');
  })
}

// 修改课程成员数量
const handleUpdateCourseNumber = async (courseId) => {
  await updateCourseNumber(Number(courseId),{number:1})
}


</script>

<template>
  <el-dialog v-model="isJoinCourse" title="加入课程" width="500px" align-center>
      <el-input v-model="invite" placeholder="请输入邀请码" style="margin-top: 20px"/>
    <div style="  display: flex;justify-content: center; /* 水平居中 */margin-top: 20px">
      <el-button type="primary" @click="emit('close');">取消</el-button>
      <el-button type="primary" @click="handleJoinCourse">确认</el-button>
    </div>
  </el-dialog>
</template>


<style scoped lang="less">

</style>